//
//  InBrandTableViewCell.m
//  AnXin100
//
//  Created by 王合润 on 10/18/18.
//  Copyright © 2018 tzhg. All rights reserved.
//

#import "InBrandTableViewCell.h"
#import "BrandCollectionViewCell.h"
@interface InBrandTableViewCell ()<UICollectionViewDelegate, UICollectionViewDataSource>

@property (nonatomic, strong) UICollectionView *brandCollectionView;

@property (nonatomic, strong) UIView *backView;

@property (nonatomic, strong) UILabel *titleLabel;

@property (nonatomic, strong) UIButton *nextPageBtn;

@property (nonatomic, strong) UIButton *beforePageBtn;

@end

@implementation InBrandTableViewCell

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    self = [super initWithStyle:style reuseIdentifier:reuseIdentifier];
    if (self) {
        [self creatCell];
    }
    return self;
}

- (void)creatCell {
    
    _backView = [[UIView alloc] init];
    [self.contentView addSubview:_backView];
    
    _titleLabel = [[UILabel alloc] init];
    [_backView addSubview:_titleLabel];
    
    UICollectionViewFlowLayout *layout = [[UICollectionViewFlowLayout alloc] init];
    layout.minimumLineSpacing = 0;
    layout.minimumInteritemSpacing = 0;
    layout.sectionInset = UIEdgeInsetsMake(0, 0, 0, 0);
    layout.itemSize = CGSizeMake((SCREEN_WIDTH - 24 - 39) / 4.0, 59);
    layout.scrollDirection = UICollectionViewScrollDirectionHorizontal;

    _brandCollectionView = [[UICollectionView alloc] initWithFrame:CGRectMake(39, 10, SCREEN_WIDTH - 39 - 24, 118) collectionViewLayout:layout];
    _brandCollectionView.backgroundColor = _backView.backgroundColor;
    _brandCollectionView.delegate = self;
    _brandCollectionView.dataSource = self;
    _brandCollectionView.pagingEnabled = YES;
    _brandCollectionView.showsHorizontalScrollIndicator = NO;
    [_brandCollectionView registerClass:[BrandCollectionViewCell class] forCellWithReuseIdentifier:@"BrandCollectionViewCell"];
    [_backView addSubview:_brandCollectionView];
    
    _beforePageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [_beforePageBtn setTitle:@"上一页" forState:UIControlStateNormal];
    _beforePageBtn.titleLabel.font = FONT_FOURTEEN;
    _beforePageBtn.backgroundColor = [UIColor whiteColor];
    [_beforePageBtn setTitleColor:[UIColor colorWithHex:0xFF9E05] forState:UIControlStateNormal];
    [_beforePageBtn addTarget:self action:@selector(beforePageAction) forControlEvents:UIControlEventTouchUpInside];
    [_backView addSubview:_beforePageBtn];
    
    _nextPageBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    _nextPageBtn.backgroundColor = [UIColor whiteColor];
    [_nextPageBtn setTitle:@"下一页" forState:UIControlStateNormal];
    _nextPageBtn.titleLabel.font = FONT_FOURTEEN;
    [_nextPageBtn setTitleColor:[UIColor colorWithHex:0x29B566] forState:UIControlStateNormal];
    [_nextPageBtn addTarget:self action:@selector(nextPageAction) forControlEvents:UIControlEventTouchUpInside];
    [_backView addSubview:_nextPageBtn];
    
    
}

- (void)layoutSubviews {
    
    _backView.frame = CGRectMake(12, 20, SCREEN_WIDTH - 24, self.mj_h - 40);
    _backView.backgroundColor = [UIColor groupTableViewBackgroundColor];
    _backView.layer.cornerRadius = 10;
    _backView.layer.masksToBounds = YES;
    
    _titleLabel.frame = CGRectMake(0, 36, 39, self.mj_h - 36 * 2 - 40);
    _titleLabel.textColor = [UIColor whiteColor];
    _titleLabel.font = FONT_FOURTEEN;
    _titleLabel.layer.cornerRadius = 10;
    _titleLabel.layer.masksToBounds = YES;
    _titleLabel.backgroundColor = COLOR_GREEN;
    
    _beforePageBtn.frame = CGRectMake(39 + (_brandCollectionView.mj_w - 88 - 28) / 2.0, _backView.mj_h - 30, 44, 20);
    _nextPageBtn.frame = CGRectMake(CGRectGetMaxX(_beforePageBtn.frame) + 28, _beforePageBtn.mj_y, 44, 20);

}

#pragma mark - UICollectionView
- (NSInteger)collectionView:(UICollectionView *)collectionView numberOfItemsInSection:(NSInteger)section {
    
    return 20;
}

- (UICollectionViewCell *)collectionView:(UICollectionView *)collectionView cellForItemAtIndexPath:(NSIndexPath *)indexPath {
    
    BrandCollectionViewCell *cell = [collectionView dequeueReusableCellWithReuseIdentifier:@"BrandCollectionViewCell" forIndexPath:indexPath];
    return cell;
}

- (void)collectionView:(UICollectionView *)collectionView didSelectItemAtIndexPath:(NSIndexPath *)indexPath {
    self.enterStore();
}

- (void)setSelected:(BOOL)selected animated:(BOOL)animated {
    [super setSelected:selected animated:animated];

}

- (void)beforePageAction {
    
}

- (void)nextPageAction {
    
}


@end
